<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996 15899929162
// +----------------------------------------------------------------------
namespace app\common\dao\housing;

use app\common\dao\BaseDao;
use app\common\model\housing\HousingFacilityModel;

class HousingFacilityDao extends BaseDao
{

    /**
     * @return HousingFacilityModel
     */
    protected function getModel(): string
    {
        return HousingFacilityModel::class;
    }

    public function search(array $where, int $propertyId = null)
    {
        return $this->getModel()::getDB()
            ->when($propertyId !== null, function ($query) use ($propertyId) {
                $query->where('property_id', $propertyId);
            })
            ->when(isset($where['housing_id']) && $where['housing_id'] !== '', function ($query) use ($where) {
                $query->where('housing_id', intval($where['housing_id']));
            })
            ->when(isset($where['facility_id']) && $where['facility_id'] !== '', function ($query) use ($where) {
                $query->where('facility_id', intval($where['facility_id']));
            });
    }


    /**
     * 清空设施信息
     * @param int $resourceId
     * @return bool
     *
     * @author Amos
     * 2024-06-05 18:06
     */
    public function clearFacility(int $housingId)
    {
        return $this->getSearch([
            'housing_id' => $housingId,
        ])->delete();
    }

}
